package bd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class DataBaseConection {
	
	public static Connection conn;
	private static DataBaseConection dataBaseConection;

	private DataBaseConection() {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			// Con un tunel se puede trabajar desde las casas y no hace falta estar
			// fisicamente en los laboratorios del ITBA
			String url = "jdbc:oracle:thin:@localhost:1521:ITBA";
			conn = DriverManager.getConnection(url, "npurita", "123456");
			conn.setAutoCommit(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static DataBaseConection getInstance() {
		if (dataBaseConection == null) {
			dataBaseConection = new DataBaseConection();
		}
		return dataBaseConection;
	}
	
	public synchronized void printDate() throws SQLException {
		Statement stmt = conn.createStatement();
		ResultSet resultSet = stmt.executeQuery("select sysdate from dual");
		resultSet.next();
		System.out.println(resultSet.getDate(1));
	    stmt.close();
	}
	
}
